<!DOCTYPE html>
<html lang="en">

	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<meta name="format-detection" content="telephone=no, email=no" />
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/vant.css">
		<link rel="stylesheet" type="text/css" href="../css/base.css" />
		<link rel="stylesheet" type="text/css" href="../css/local.css" />
		<script type="text/javascript" src="../script/jquery.js"></script>
		<script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
		<script type="text/javascript" src="../script/vue.min.js"></script>
		<script src="../script/vant.min.js"></script>
		<script type="text/javascript" src="../script/fastclick.js"></script>
		<script type="text/javascript" src="../script/base.js"></script>
		<style>
			.pd {
				padding: 10px;

			}

			.pd>div {
				background: #fff;
				overflow: hidden;
				border-radius: 6px;

			}

			.ov {
				overflow: hidden;
			}

			.p {
				padding: 5px;
			}

			.row {
				position: relative;
			}

			.row .img {
				width: 100px;
				height: 80px;
				border-radius: 4px;
				overflow: hidden;
			}

			.row .img img {
				width: 100%;
				height: 100%;
			}

			.row .desc {
				position: absolute;
				top: 0;
				left: 100px;
				right: 0;
				bottom: 0;
				padding-left: 5px;
			}

			.row .desc .title {
				font-size: 14px;
				height: 40px;
				line-height: 20px;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
			}

			.row .desc .title .hot {
				color: #fff;
				background: #cd1b21;
				font-size: 12px;
				border-radius: 2px;
				margin-right: 5px;
				display: inline-block;
				line-height: 16px;
				padding: 0 2px;
				vertical-align: middle;
			}

			.tag {
				position: relative;
				overflow: hidden;
			}

			.tag span {
				color: #cd1b21;
				border: 1px solid #ff6e73;
				font-size: 12px;
				border-radius: 2px;
				display: inline-block;
				line-height: 16px;
				padding: 0 2px;
				vertical-align: middle;
				transform: scale(0.8);
				-webkit-transform-origin-x: 0;
				float: left;
			}

			.tag span:first-child {
				margin-left: 0;
			}

			.row .desc .sub-title {
				font-size: 12px;
				color: #969799;
				line-height: 20px;
				height: 40px;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.row .desc .sub-title * {
				vertical-align: middle;
			}

			.van-radio__icon {
				display: none;
			}

			.van-address-list {
				padding: 0 0 100px 0;
			}

			.van-address-item {
				border-radius: 0;
			}
		</style>

	</head>

	<body>
		<div id="app" v-cloak>
			<div class="init-full">
				<van-nav-bar class="head" title="收货地址" left-arrow @click-left="onClickLeft"></van-nav-bar>
				<div class="body-with-bottom">
					<div class="content">
						<van-address-list v-model="chosenAddressId" :list="showAddressList" default-tag-text="默认"
							@select="selectItem" @add="onAdd" @edit="onEdit"></van-address-list>
					</div>
					<van-loading v-if="showLoading" />
				</div>
			</div>
		</div>
	</body>

	<!-- 调用 uniapp webview 的 api ，记得需要写在 body 标签下面 -->
	<script src="../../../assets/script/uni.webview.1.5.4.js"></script>
	<script type="text/javascript">
		var vm;
		//$('.init-full').show();


		vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				serverIP: 'http://' + FLD.serverIP,
				shoppingMallServerIP: 'http://' + FLD.shoppingMallServerIP,
				chosenAddressId: 0,
				addressList: [],
				showAddressList: []
			},
			created: function() {
				this.getAddressList();

				window.localStorage.removeItem('addressInfo')
			},
			methods: {
				getAddressList() {
					var that = this;
					that.showLoading = true;
					FLD.ajax('sp_getShipAddress', {}, function(res) {
						that.showLoading = false;
						that.addressList = res.ds;
						var adressList = [];
						for (var i in that.addressList) {
							adressList.push({
								id: that.addressList[i].ShippingId,
								name: that.addressList[i].ShipTo,
								tel: that.addressList[i].TelPhone,
								address: that.addressList[i].Address,
								isDefault: that.addressList[i].IsDefault
							})
						}
						that.showAddressList = adressList;
					})
				},
				selectItem(item, index) {
					var that = this;
					if (window.localStorage.getItem('AddressType') && window.localStorage.getItem('AddressType') ==
						'order') {
						var data = that.addressList[index];

						window.localStorage.setItem('addressInfo', JSON.stringify(data))
						window.localStorage.removeItem('AddressType')
						window.history.back()
						// api.sendEvent({
						// 	name: 'changeAddress',
						// 	extra: {
						// 		data: data
						// 	}
						// });
						// api.closeWin();
					}
				},
				onAdd() {
					var that = this;
					window.location.href = './addressEdit.html'
					// api.openWin({
					// 	name: 'addressEdit',
					// 	url: 'addressEdit.html',
					// 	reload: true,
					// 	slidBackEnabled: false,
					// })
				},
				onEdit(item, index, event) {
					var that = this;
					window.location.href = './addressEdit.html';
					window.localStorage.setItem('addressInfo', JSON.stringify(that.addressList[index]))

					// api.openWin({
					// 	name: 'addressEdit',
					// 	url: 'addressEdit.html',
					// 	reload: true,
					// 	slidBackEnabled: false,
					// 	pageParam: {
					// 		data: that.addressList[index]
					// 	}
					// })
				},
				onClickLeft() {
					uni.navigateBack()
				}
			}
		})
	</script>

</html>